//
//  MainController.swift
//  weibo-mxm
//
//  Created by 马晓敏 on 16/1/11.
//  Copyright © 2016年 马晓敏. All rights reserved.
//

import UIKit

class MainController: UITabBarController {
//系统tabber为只读属性 不能狗直接修改,可以通过KVC修改
    
    
 //MARK:按钮的监听事件
@objc  private    func plusBtnClick(){
    
    print(__FUNCTION__)
    
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
       print(tabBar.classForCoder)
     let  mainTabBar = MainTabar()
      setValue(mainTabBar, forKey: "tabBar")
     mainTabBar.plusBtn.addTarget(self, action: Selector("plusBtnClick"), forControlEvents: UIControlEvents.TouchUpInside)
        
       print(tabBar.classForCoder)
        
        
        
    //控制器的入口
    addChildViewControllers()
    }
//添加子控制器
    func addChildViewControllers(){
    addChildViewController(HomeController(),imageName: "tabbar_home" , title: "首页")
    addChildViewController(MessageController(),imageName: "tabbar_message_center" , title: "消息")
    addChildViewController(DIscoverController(),imageName: "tabbar_discover" , title: "发现")
    addChildViewController(ProfileController(),imageName: "tabbar_profile" , title: "我")
        
    
    }
       func addChildViewController(vc:UIViewController,imageName:String,title:String){
    //let home = HomeController()
        vc.tabBarItem.image = UIImage(named: imageName)
        //home.tabBarItem.title = "首页"
       //home.navigationItem.title = "新浪微博"
        
  //   self.tabBar.tintColor = UIColor.orangeColor()
        
//      vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted"
//        )?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//      //修改图片的显示样式
//        
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState:.Selected)
        
    vc.title = title
    let nav = UINavigationController(rootViewController: vc)
        
    addChildViewController(nav)
    
    
    }
}
